//
//  UserCmdProcessor.m
//  SmartTalk
//
//  Created by 陈勃 on 14-12-30.
//  Copyright (c) 2014年 gameabc. All rights reserved.
//

#import "UserCmdProcessor.h"
#import "NetWorkManager.h"
#import "TTDefines.h"
@implementation UserCmdProcessor
-(void)loginWith:(NSString *)name pwd:(NSString *)pwd  callback:(CmdProcessorCallbackBLock )resp
{
    self.transid = [[NetWorkManager sharedInstance] getLongTransIdIndex];
    self.reqDict = @{@"transid":@([[NetWorkManager sharedInstance] getLongTransIdIndex]),
                     @"action":@(TTNetActionTypeLogin),
                     @"name":name,
                     @"pwd":pwd};
    self.respBlock = resp;
}

-(BOOL)handleLoginResp:(NSInteger)actionType info:(NSDictionary *)rspDiction
{
    self.rspDict = [rspDiction copy];
    //int userid = [[rspDiction objectForKey:KEY_RESULT_CODE] intValue];
    self.rspcode = 0;
    
    self.respBlock(self);
    return YES;
}

-(void)getFriendList:(int)status callback:(CmdProcessorCallbackBLock )resp
{
    self.transid = [[NetWorkManager sharedInstance] getLongTransIdIndex];
    self.reqDict = @{@"transid":@([[NetWorkManager sharedInstance] getLongTransIdIndex]),
                     @"action":@(TTNetActionTypeFriendList),
                     @"status":@(status)};
    self.respBlock = resp;
}

-(BOOL)hanleFriendList:(NSInteger)actionType info:(NSDictionary *)rspDiction
{
    self.rspDict = @{KEY_RESULT_ARRAY:rspDiction[@"data"]};
    self.rspcode = 0;
    
    self.respBlock(self);
    return YES;
}

-(BOOL)handle:(NSInteger)actionType info:(NSDictionary *)rspDict
{
//    if (actionType == TTNetActionTypeLogin) {
//        return [self handleLoginResp:actionType info:rspDict];
//    }
    switch (actionType) {
        case TTNetActionTypeLogin:
           return [self handleLoginResp:actionType info:rspDict];
        case TTNetActionTypeFriendList:
            return [self hanleFriendList:actionType info:rspDict];
        default:
            break;
    }
    return NO;
}

@end
